package com.lin.filegraph.utils.parser.node;

import com.lin.filegraph.utils.parser.simpleast.SimpleASTHelper;

import java.util.ArrayList;
import java.util.List;

/**
 * @description:
 * @author: linhuaixu
 * @time: 2023/5/18 10:15
 */

public class JPackageNode extends JTreeNode {

    private String packageName = null;

    public JPackageNode(String filePath, String packageName) {
        super(filePath, null);
        this.packageName = packageName;
    }

    public String getPackageName() {
        return packageName;
    }

    public List<JFileNode> getAllFiles() {
        List<JFileNode> fileNodeList = new ArrayList<JFileNode>();// �������ļ������б�
        List<? extends JTreeNode> tempList = super.getChildrenNodeList();
        for (JTreeNode basedNode : tempList) {
            if (basedNode instanceof JFileNode) {
                JFileNode fileNode = (JFileNode) basedNode;
                fileNodeList.add(fileNode);
            }
        }
        return fileNodeList;
    }

    public List<JFileNode> getAllFilesOfSamePgk() {
        JProjectNode root = this.getRoot();
        List<JFileNode> fileNodeList = new ArrayList<JFileNode>();// �������ļ������б�
        List<JPackageNode> listOfPkgs = SimpleASTHelper.getListPkgsByName(packageName, root);
        for(JPackageNode pkg : listOfPkgs) {
            fileNodeList.addAll(pkg.getAllFiles());
        }
        return fileNodeList;
    }

    @Override
    public String toString() {
        return "[PackageNode] " + packageName;
    }
}